

from rest_framework import serializers
from goods.models import SPU,Brand,GoodsCategory


class CateSimpleSerializer(serializers.ModelSerializer):

    class Meta:
        model = GoodsCategory
        fields = [
            'id',
            'name'
        ]


class BrandSimpleSerializer(serializers.ModelSerializer):

    class Meta:
        model = Brand
        fields = [
            'id',
            'name'
        ]



class SPUModelSerializer(serializers.ModelSerializer):
    brand = serializers.StringRelatedField() # 默认read_only=True，只参与序列化
    brand_id = serializers.IntegerField()
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()

    class Meta:
        model = SPU
        # fields = '__all__' # 自动映射id隐藏字段，和，显示定义的字段
        exclude = ['category1', 'category2', 'category3'] # 我们接口中无需操作category1，category2，category3